import 'package:flutter/material.dart';
import 'Router.dart';
import '../main_container.dart';
import '../pages/ArticleDetail/ArticleDetailPage.dart';
import '../pages/kuaixun/kuaixunPage.dart';
import '../pages/search/SearchPage.dart';
import '../pages/mine/MinePage.dart';

class RouteGenerator {
  static Route<dynamic> generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case AppRoutes.home:
        return MaterialPageRoute(builder: (_) => const MainContainer());

      case AppRoutes.articleDetail:
        final args = settings.arguments as Map<String, dynamic>?;
        return MaterialPageRoute(
          builder: (_) => ArticleDetailPage(articleId: args?['id'] ?? 0),
        );

      case AppRoutes.newsDetail:
        final args = settings.arguments as Map<String, dynamic>?;
        return MaterialPageRoute(
          builder: (_) => ArticleDetailPage(articleId: args?['id'] ?? ''),
        );

      case AppRoutes.category:
        return MaterialPageRoute(builder: (_) => CategoryPage());

      case AppRoutes.search:
        return MaterialPageRoute(builder: (_) => const SearchPage());

      case AppRoutes.profile:
        return MaterialPageRoute(builder: (_) => const ProfilePage());

      default:
        return _errorRoute();
    }
  }

  static Route<dynamic> _errorRoute() {
    return MaterialPageRoute(
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text('页面未找到')),
          body: const Center(child: Text('页面未找到')),
        );
      },
    );
  }
}
